#define DEBUG
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=4000000;

static int l[2*maxn+1], r[2*maxn+1], lins=0;
static char v[2*maxn+1];

int append(int o, int t) {
  l[t]=o;
  r[t]=r[o];
  return r[l[t]] = l[r[t]] = t;
}

int del(int o) {
  r[l[o]] = r[o];
  l[r[o]] = l[o];
  l[o] = r[o] = 0;
  return o;
}

int next(int o) {
  if (v[r[o]] && l[r[r[o]]]!=r[o]) swap(l[r[r[o]]], r[r[r[o]]]);
  return r[o];
}

int prev(int o) {
  if (v[l[o]] && r[l[l[o]]]!=l[o]) swap(l[l[l[o]]], r[l[l[o]]]);
  return l[o];
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  int first, end, cur[2];
  first = cur[0] = cur[1] = ++lins;
  v[lins]='\0';
  end = ++lins, v[lins]='\0';
  r[first] = end, l[end] = first;
  static char str[maxn+1];
  scanf("%s", str);
  for (int i=0; str[i]; i++) {
    cur[1] = append(cur[1], ++lins), v[lins]=str[i];
  }

  bool flag=true;
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    char opt, w, c;
    int t;
    scanf(" %c ", &opt);
    switch (opt) {
    case '>' :
      scanf(" %c ", &w);
      t= w=='R';
      if (v[next(cur[t])]) {
        if (cur[0]==cur[1]) flag = t==1;
        cur[t] = next(cur[t]);
        printf("T\n");
      } else printf("F\n");
      break;
    case '<' :
      scanf(" %c ", &w);
      t= w=='R';
      if (v[cur[t]]) {
        if (cur[0]==cur[1]) flag = t==0;
        cur[t] = prev(cur[t]);
        printf("T\n");
      } else printf("F\n");
      break;
    case 'I' :
      scanf(" %c %c ", &w, &c);
      t = w=='R';
      if (cur[0]==cur[1]) cur[t] = cur[!t] = append(cur[t], ++lins), v[lins]=c;
      else cur[t] = append(cur[t], ++lins), v[lins]=c;
      printf("T\n");
      break;
    case 'D' :
      scanf(" %c ", &w);
      t = w=='R';
      if (v[next(cur[t])]) {
        del(next(cur[t]));
        printf("T\n");
      } else printf("F\n");
      break;
    case 'R' :
      if (cur[0]!=cur[1] && flag) {
        cur[1] = next(cur[1]);
        l[r[cur[0]]]=r[r[cur[0]]], r[r[cur[0]]]=cur[1];
        r[l[cur[1]]]=l[l[cur[1]]], l[l[cur[1]]]=cur[0];
        swap(r[cur[0]], l[cur[1]]);
        cur[1] = prev(cur[1]);
        printf("T\n");
      } else printf("F\n");
      break;
    case 'S' :
      for (int i=next(first); v[i]; i=next(i)) printf("%c", v[i]);
      printf("\n");
      break;
    }
  }
  
  fclose(stdin);
  fclose(stdout);
  return 0;
}
